package cn.skyclass.controls
{
	import cn.skyclass.events.EventNotification;
	import cn.skyclass.events.PopUpEvent;
	
	import flash.display.Sprite;
	
	import mx.controls.Alert;
	import mx.events.CloseEvent;
		
	/**
	 * 自定义的 Alert 类，其 show 方法接口和 mx.controls.Alert.show 基本一致
	 * 在弹出窗口之前发布 PopUpEvent.POP_UP_OPEN 事件
	 * 在弹出窗口之后发布 PopUpEvent.POP_UP_CLOSE 事件
	 */
	public class CustomAlert extends Alert
	{
		/**
		 * enInstanceName : 用于发布 PopUpEvent 事件的全局事件模型的实例名称
		 * 如果此值为空，则使用默认的全局事件模型
		 */		
		public static function show(text:String = "", title:String = "", flags:uint = 0x4, 
			parent:Sprite = null, closeHandler:Function = null, 
			iconClass:Class = null, defaultButtonFlag:uint = 0x4, enInstanceName:String=null):Alert{
			
			if(enInstanceName == null){
				enInstanceName = EventNotification.DEFAULT_INSTANCE_NAME;
			}	
			
			var en:EventNotification = EventNotification.getInstance(enInstanceName);
			en.dispatchEvent(new PopUpEvent(PopUpEvent.POP_UP_OPEN));
			
			return Alert.show(text, title, flags, parent, close, iconClass, defaultButtonFlag);
			
			function close(e:CloseEvent):void{
				if(closeHandler != null){
					closeHandler.apply(closeHandler, new Array(e));
				}
				en.dispatchEvent(new PopUpEvent(PopUpEvent.POP_UP_CLOSE));
			}			
		}
		
		
		/**
		 * 设置中文的按钮文字
		 */
		public static function setChineseAlertLabel():void{
			Alert.yesLabel = "是";
			Alert.noLabel = "否";
			Alert.okLabel = "确定";			
			Alert.cancelLabel = "取消";
		}			
	}
}